<!--
	This file is part of ELCube.
	ELCube is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	ELCube is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.
	You should have received a copy of the GNU Affero General Public License
	along with ELCube.  If not, see <https://www.gnu.org/licenses/>.
-->
<template>
    <nk-def-card title="入参">
        <vxe-toolbar v-if="editMode">
            <template v-slot:buttons>
                <vxe-button icon="fa fa-plus" status="perfect" size="mini" @click="xTableAdd()">新增</vxe-button>
            </template>
        </vxe-toolbar>
        <vxe-table
                ref="xTable"
                row-key
                auto-resize
                keep-source
                resizable
                size="mini"
                border=inner
                :data="def.params"
                :edit-config="{trigger: 'click', mode: 'row', showIcon: editMode, showStatus: true,activeMethod}">
            <vxe-column field="name" width="40%" title="参数" :edit-render="{name: '$input',props: {type: 'text',maxlength:16}}"></vxe-column>
            <vxe-column field="desc"             title="描述" :edit-render="{name: '$input',props: {type: 'text',maxlength:16}}"></vxe-column>
            <vxe-column field="required"         title="必填" :edit-render="{name: '$switch',props: {}}"></vxe-column>
            <vxe-column field="defaultValueSpEL" title="默认" :edit-render="{name: '$input',props: {type: 'text',maxlength:200}}"></vxe-column>
            <vxe-column >
                <template v-slot="{seq,items}">
                    <span v-if="editMode" style="margin-right: 10px;" @click="xTableRemove(seq)">
                        <a-icon type="delete" />
                    </span>
                </template>
            </vxe-column>
        </vxe-table>
    </nk-def-card>
</template>

<script>
    import MixinDef from "MixinDef";

    export default {
        mixins:[new MixinDef({params:[]})],
        computed:{
        },
        created() {
        },
        methods:{
            activeMethod(){return this.editMode;},
            xTableAdd(){
                if(!this.def.params){
                    this.$set(this.def,'params',[]);
                }
                const row = {};
                this.def.params.push(row);
                this.$refs.xTable.setActiveRow(row);
            },
            xTableRemove(i){
                this.def.params.splice(i-1,1);
            }
        }
    }
</script>

<style scoped>

</style>